package com.just.school_campus.service.impl;

import com.just.school_campus.dao.FeedBackMapper;
import com.just.school_campus.model.FeedBack;
import com.just.school_campus.model.FeedBackExample;
import com.just.school_campus.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedBackMapper feedbackDao;

    @Override
    public int submitFeedback(FeedBack feedback) {
        synchronized (this) {
            while (true) {
                String feedbackId = UUID.randomUUID().toString();
                FeedBackExample example = new FeedBackExample();
                example.createCriteria().andFeedbacksIdEqualTo(feedbackId);
                FeedBack one = feedbackDao.selectByExample(example).get(0);
                if (one == null) {
                    feedback.setFeedbacksId(feedbackId);
                    return feedbackDao.insertSelective(feedback);
                }
            }
        }
    }
}
